<?php
// +----------------------------------------------------------------------
// | File create_time 2012年4月1日
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: zhangrui <zhangrui_guitar@163.com>
// +----------------------------------------------------------------------
// | Remark: 翼码科技彩信交易
// +----------------------------------------------------------------------


/**
 +-----------------------------
 * 彩信交易类
 +-----------------------------
 */
Class YimaMms {
    static public $organization='1553100100010000'; //机构码(测试)
    static public $url = "http://222.44.51.34/new_bts_serv/bts_serv.do"; //委托交易请求地址(测试)

    //private $url = "http://221.130.183.53/bts_serv/bts_serv.do"; //委托交易请求地址
    //private $organization='2600000000030200'; //机构码

    /**
	 +----------------------------------------------------------
	 * 发送条码
	 +----------------------------------------------------------
	 * @access public
	 +----------------------------------------------------------
	 * @param $info array 请求彩信所需信息
	 +----------------------------------------------------------
	 * @return xml
	 +----------------------------------------------------------
	 */
    public function send_mms($info){
        $xml='<?xml version="1.0" encoding="GB2312"?>
                <business_trans version="2.0">
                	<request_type>generated_commission_request</request_type>
                	<organization>' . self::$organization . '</organization>
                	<req_seq>' . $info['req_seq'] . '</req_seq>
                	<user_id>' . $info['user_id'] . '</user_id>
                	<generated_commission_request>
                    	 <batch_no>' . $info['batch_no'] . '</batch_no>
                    	 <phone_req>' . $info['phone_req'] . '</phone_req>
                    	 <phone_rece>' . $info['phone_rece'] . '</phone_rece>
                    	 <phone_type></phone_type>
                    	 <send_type>bbb</send_type>
                    	 <info_title>' . $info['info_title'] . '</info_title>
                    	 <notes>' . $info['notes'] . '</notes>
                    	 <mms_notes>'. $info['mms_notes'] .'</mms_notes>
                    	 <begin_time>' . $info['begin_time'] . '</begin_time>
                    	 <valid_time>' . $info['valid_time'] . '</valid_time>
                    	 <total_amt>' . $info['total_amt'] . '</total_amt>
                    	 <total_times>' . $info['total_times'] . '</total_times>
                    	 <pin_setting>
                        	  <pin_md5></pin_md5>
                        	  <pin_try_times></pin_try_times>
                    	 </pin_setting>
                    	 <service>
                        	  <serv_code>' . $info['serv_code'] . '</serv_code>
                        	  <print_text>' . $info['print_text'] . '</print_text>
                        	  <auth_type>
                        		<org_amt>' . $info['org_amt'] . '</org_amt>
                        		<org_times>' . $info['org_times'] . '</org_times>
                        	  </auth_type>
                    	 </service>
                	</generated_commission_request>
                 </business_trans>';
        $data = array('xml' => $xml);
        return $res = Utility::DoPost(self::$url, $data);
    }
    
    /**
	 +----------------------------------------------------------
	 * 重发条码
	 +----------------------------------------------------------
	 * @access public
	 +----------------------------------------------------------
	 * @param $yimamms array 二维码信息记录表
	 +----------------------------------------------------------
	 * @return bool
	 +----------------------------------------------------------
	 */
    public function resend_mms($yimamms){
        $xml = '<?xml version="1.0" encoding="GB2312"?>
				<business_trans version="2.0">
    				<request_type>er_resend_request</request_type>
    				<organization>' . self::$organization . '</organization>
    				<req_seq>' . '1000000286' . date('YmdHis', time()) . rand(100000, 999999) . '</req_seq>
    				<user_id>' . $yimamms["user_id"] . '</user_id>
    				<er_resend_request>
    				    <ori_seq>'. $yimamms["id"] . '</ori_seq>
    				</er_resend_request>
				</business_trans>';
        $data = array('xml' => $xml);
        $res = Utility::DoPost(self::$url, $data);
		$doc = new DOMDocument();
		$doc->loadXML($res);
		$sys_seq = $doc->getElementsByTagName("sys_seq")->item(0)->nodeValue;
		$rs = $doc->getElementsByTagName("id")->item(0)->nodeValue;
		$msg = $doc->getElementsByTagName("comment")->item(0)->nodeValue;
		if('0000' == $rs) {
		    return true;
		}else {
		    return $msg;
		}
    }
    
    /**
	 +----------------------------------------------------------
	 * 转发条码
	 +----------------------------------------------------------
	 * @access public
	 +----------------------------------------------------------
	 * @param $yimamms array 二维码信息记录表
	 +----------------------------------------------------------
	 * @return bool
	 +----------------------------------------------------------
	 */
    public function changesend_mms($yimamms){
        $xml = '<?xml version="1.0" encoding="GB2312"?>
				<business_trans version="2.0">
    				<request_type>er_sendto_request</request_type>
    				<organization>' . self::$organization . '</organization>
    				<req_seq>' . '1000000286' . date('YmdHis', time()) . rand(100000, 999999) . '</req_seq>
    				<user_id>' . $yimamms["user_id"] . '</user_id>
    				<er_sendto_request>
    				    <ori_seq>'. $yimamms["id"] . '</ori_seq>
    				    <phone>'. $yimamms["mobile"] . '</phone>
    				    <send_type>'. $yimamms["type"] . '</send_type>
    				</er_sendto_request>
				</business_trans>';
        $data = array('xml' => $xml);
        $res = Utility::DoPost(self::$url, $data);
		$doc = new DOMDocument();
		$doc->loadXML($res);
		$sys_seq = $doc->getElementsByTagName("sys_seq")->item(0)->nodeValue;
		$rs = $doc->getElementsByTagName("id")->item(0)->nodeValue;
		$msg = $doc->getElementsByTagName("comment")->item(0)->nodeValue;
		if('0000' == $rs) {
		    return true;
		}else {
		    return $msg;
		}
    }
    
    /**
	 +----------------------------------------------------------
	 * 转发条码
	 +----------------------------------------------------------
	 * @access public
	 +----------------------------------------------------------
	 * @param $yimamms array 查询二维码状态
	 +----------------------------------------------------------
	 * @return array
	 +----------------------------------------------------------
	 */
    public function sync_mms($yimamms){
        $xml = '<?xml version="1.0" encoding="GB2312"?>
				<business_trans version="2.0">
    				<request_type>query_request</request_type>
    				<organization>' . self::$organization . '</organization>
    				<req_seq>' . '1000000286' . date('YmdHis', time()) . rand(100000, 999999) . '</req_seq>
    				<user_id>' . $yimamms["user_id"] . '</user_id>
    				<query_request>
    				    <ori_seq>'. $yimamms["id"] . '</ori_seq>
    				</query_request>
				</business_trans>';
        $data = array('xml' => $xml);
        $res = Utility::DoPost(self::$url, $data);
		$doc = new DOMDocument();
		$doc->loadXML($res);
		return $sys_seq = $doc->getElementsByTagName("seq_status")->item(0)->nodeValue;
    }
    
    /**
	 +----------------------------------------------------------
	 * 转发条码
	 +----------------------------------------------------------
	 * @access public
	 +----------------------------------------------------------
	 * @param $yimamms array 二维码撤销
	 +----------------------------------------------------------
	 * @return bool
	 +----------------------------------------------------------
	 */
    public function cancel_mms($yimamms){
        $xml = '<?xml version="1.0" encoding="GB2312"?>
				<business_trans version="2.0">
    				<request_type>commission_cancel_request</request_type>
    				<organization>' . self::$organization . '</organization>
    				<req_seq>' . '1000000286' . date('YmdHis', time()) . rand(100000, 999999) . '</req_seq>
    				<user_id>' . $yimamms["user_id"] . '</user_id>
    				<commission_cancel_request>
    				    <ori_seq>'. $yimamms["id"] . '</ori_seq>
    				</commission_cancel_request>
				</business_trans>';
        $data = array('xml' => $xml);
        $res = Utility::DoPost(self::$url, $data);
		$doc = new DOMDocument();
		$doc->loadXML($res);
		$sys_seq = $doc->getElementsByTagName("sys_seq")->item(0)->nodeValue;
		$rs = $doc->getElementsByTagName("id")->item(0)->nodeValue;
		$msg = $doc->getElementsByTagName("comment")->item(0)->nodeValue;
		if('0000' == $rs) {
		    return true;
		}else {
		    return $msg;
		}
    }

}